package com.gzdh.dishrecognition.ui.base;

import android.app.Presentation;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.KeyEvent;
import android.widget.FrameLayout;

import androidx.annotation.LayoutRes;



public abstract class BasePresentation extends Presentation {

    public BasePresentation(Context outerContext, Display display) {
        super(outerContext, display);

        setContentView(getLayoutId());
//        FrameLayout rootView = findViewById(R.id.framePreMain);
//        getLayoutInflater().inflate(getLayoutId(), rootView);
        initView();
        initData();
    }

    @LayoutRes
    protected abstract int getLayoutId();

    protected abstract void initView();

    protected abstract void initData();

    @Override
    public void dismiss() {
        hide();
        super.dismiss();
    }

    public void onEvent(Object message) {

    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                return onKeyEventBack(event);
            } else if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                return onKeyEventEnter(event);
            } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP
                    || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) {
                return onKeyEventUpAndDown(event);
            } else if (event.getKeyCode() == KeyEvent.KEYCODE_SETTINGS) {
                return onKeyEventSetting(event);
            } else if (event.getKeyCode() == KeyEvent.KEYCODE_F1) {
                return onKeyEventFunction(event);
            } else if (event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_0
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_1
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_2
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_3
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_4
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_5
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_6
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_7
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_8
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_9
                    || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_DOT
                    || event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
                return onKeyEventNum(event);
            }
        }
        return super.dispatchKeyEvent(event);
    }

    /**
     * 取消键
     */
    public boolean onKeyEventBack(KeyEvent event) {
        return super.dispatchKeyEvent(event);
    }

    /**
     * 确认键
     */
    public boolean onKeyEventEnter(KeyEvent event) {
        return super.dispatchKeyEvent(event);
    }

    /**
     * 数字
     */
    public boolean onKeyEventNum(KeyEvent event) {
        return super.dispatchKeyEvent(event);
    }

    /**
     * 向上向下
     */
    public boolean onKeyEventUpAndDown(KeyEvent event) {
        return super.dispatchKeyEvent(event);
    }

    /**
     * 设置
     */
    public boolean onKeyEventSetting(KeyEvent event) {
        return super.dispatchKeyEvent(event);
    }

    /**
     * 功能
     */
    public boolean onKeyEventFunction(KeyEvent event) {
        return super.dispatchKeyEvent(event);
    }

}
